/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  javafx.fxml.FXML
 *  javafx.fxml.FXMLLoader
 *  javafx.fxml.Initializable
 *  javafx.scene.Node
 *  javafx.scene.control.Accordion
 *  javafx.scene.control.Button
 *  javafx.scene.control.DatePicker
 *  javafx.scene.control.TitledPane
 *  javafx.scene.layout.HBox
 *  javafx.scene.layout.VBox
 */
package com.gys.common.plugIn.dateTimePicker;

import com.gys.common.plugIn.dateTimePicker.DateTimePicker;
import com.gys.common.plugIn.dateTimePicker.HoursPicker;
import com.gys.common.plugIn.dateTimePicker.MinuteSecondPicker;
import java.io.IOException;
import java.net.URL;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.Accordion;
import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;

public class DateTimePickerPopup
extends VBox
implements Initializable {
    private final DateTimePicker parentControl;
    private final HoursPicker hoursPicker;
    private final MinuteSecondPicker minutesPicker;
    private final MinuteSecondPicker secondsPicker;
    private int hour;
    private int minute;
    private int second;
    @FXML
    private Accordion accordion;
    @FXML
    private DatePicker datePicker;
    @FXML
    private TitledPane timePane;
    @FXML
    private HBox timeButtonsPane;
    @FXML
    private Button hoursButton;
    @FXML
    private Button minutesButton;
    @FXML
    private Button secondsButton;

    public DateTimePickerPopup(DateTimePicker parentControl) {
        this.hour = ((LocalDateTime)parentControl.dateTimeProperty().get()).getHour();
        this.minute = ((LocalDateTime)parentControl.dateTimeProperty().get()).getMinute();
        this.second = ((LocalDateTime)parentControl.dateTimeProperty().get()).getSecond();
        this.parentControl = parentControl;
        this.hoursPicker = new HoursPicker(this);
        this.minutesPicker = new MinuteSecondPicker(this);
        this.secondsPicker = new MinuteSecondPicker(this);
        URL url = HoursPicker.class.getClass().getResource("/fxml/dateTimePicker/DateTimePickerPopup.fxml");
        FXMLLoader fxmlLoader = new FXMLLoader();
        try {
            fxmlLoader = new FXMLLoader(url);
        }
        catch (Exception e) {
            throw new RuntimeException(e);
        }
        fxmlLoader.setRoot(this);
        fxmlLoader.setController(this);
        try {
            fxmlLoader.load();
        }
        catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }

    public void initialize(URL location, ResourceBundle resources) {
        this.setTimeButtonText();
        this.accordion.setExpandedPane(this.timePane);
    }

    void setDate(LocalDate date) {
        this.datePicker.setValue(date);
    }

    LocalDate getDate() {
        return (LocalDate)this.datePicker.getValue();
    }

    void setTime(LocalTime time) {
        this.hour = time.getHour();
        this.minute = time.getMinute();
        this.second = time.getSecond();
        this.setTimeButtonText();
    }

    LocalTime getTime() {
        return LocalTime.of(this.hour, this.minute, this.second);
    }

    int getHour() {
        return this.hour;
    }

    void restoreTimePanel() {
        this.hour = this.hoursPicker.getHour();
        this.minute = this.minutesPicker.getValue();
        this.second = this.secondsPicker.getValue();
        this.setTimeButtonText();
        this.timePane.setContent((Node)this.timeButtonsPane);
    }

    @FXML
    void handleHoursButtonAction() {
        this.timePane.setContent((Node)this.hoursPicker);
    }

    @FXML
    void handleMinutesButtonAction() {
        this.timePane.setContent((Node)this.minutesPicker);
    }

    @FXML
    void handleSecondsButtonAction() {
        this.timePane.setContent((Node)this.secondsPicker);
    }

    @FXML
    void handleOkButtonAction() {
        this.hour = this.hoursPicker.getHour();
        this.setTimeButtonText();
        this.parentControl.hidePopup();
    }

    private void setTimeButtonText() {
        this.hoursButton.setText(String.format("%02d", this.hour));
        this.minutesButton.setText(String.format("%02d", this.minute));
    }
}

